package com.coldlz.mmp.common;

import java.util.ArrayList;
import java.util.List;

public class ListUtil {

    public static <T> List<List<T>> split(List<T> list, int len) {
        if (list == null || list.isEmpty()) {
            return new ArrayList<>();
        }
        List<List<T>> res = new ArrayList<>();
        int size = list.size() / len + list.size() % len;
        for (int i = 0; i < size; i++) {

            int fromIndex = i * len;
            int toIndex = Math.min(fromIndex + len, list.size());
            res.add(list.subList(fromIndex, toIndex));
        }
        return res;
    }
}
